﻿Public Class clsJLck
    Public Function getJlCkInList(startTime As String, endTime As String, code As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_jl_ck_in "
        szSql &= "where 1=1 "
        If startTime <> "" Then
            szSql &= " and update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and update_time <= '" + endTime + "'"
        End If
        If code <> "" Then
            szSql &= " and ck_in_code like '%" + code + "%'"
        End If
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

    Public Function getJlCkInDetailsList(code As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_jl_ck_in_details "
        szSql &= "where 1=1 "
        If code <> "" Then
            szSql &= " and ck_in_code = '" + code + "'"
        End If
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

    Public Function getJlCkOutList(startTime As String, endTime As String, code As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_jl_ck_out "
        szSql &= "where 1=1 "
        If startTime <> "" Then
            szSql &= " and update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and update_time <= '" + endTime + "'"
        End If
        If code <> "" Then
            szSql &= " and ck_out_code like '%" + code + "%'"
        End If
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

    Public Function getJlCkOutDetailsList(code As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_jl_ck_out_details "
        szSql &= "where 1=1 "
        If code <> "" Then
            szSql &= " and ck_out_code = '" + code + "'"
        End If
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

    Public Function updateInDetailsVlidity(validity As String, sys_id As String, batch_no As String, mst_value As String, into_weight As String) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "update sf.b_jl_ck_in_details set validity = ? where sys_id = ?"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, validity, sys_id)
            szSql = String.Empty
            szSql &= "UPDATE sf.b_jl_ck "
            szSql &= " SET cur_weight = cur_weight - ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " WHERE batch_no = ? and mst_value = ? "
            DBacs.ExecuteUpdateSql(szSql, -1, into_weight, batch_no, mst_value)
            szSql = String.Empty
            szSql &= "UPDATE sf.t_mst_jl "
            szSql &= " SET cur_weight = cur_weight - ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " WHERE mst_value = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, into_weight, mst_value)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
        End Try
        Return rtn
    End Function

    Public Function updateOutDetailsVlidity(validity As String, sys_id As String, batch_no As String, mst_value As String, out_weight As String) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            szSql &= "update sf.b_jl_ck_out_details set validity = ? where sys_id = ?"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, validity, sys_id)
            szSql = String.Empty
            szSql &= "UPDATE sf.b_jl_ck  "
            szSql &= " SET cur_weight = cur_weight + ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " WHERE batch_no = ? and mst_value = ? "
            DBacs.ExecuteUpdateSql(szSql, -1, out_weight, batch_no, mst_value)
            szSql = String.Empty
            szSql &= "UPDATE sf.t_mst_jl "
            szSql &= " SET cur_weight = cur_weight + ?, update_time=(SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= " WHERE mst_value = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, out_weight, mst_value)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
        End Try
        Return rtn
    End Function



End Class
